/*
 * BigInteger.cpp
 *
 *  Created on: Jun 18, 2010
 *      Author: Lukasz Spintzyk
 */

#include "BigInteger.h"



BigInteger::BigInteger(uint32_t init)
	:value(NULL)
{
	value = BN_new();
	BN_set_word(value, init);
}

BigInteger::BigInteger(const std::string& iv, uint32_t init_add)
	:value(NULL)
{
	value = BN_new();
	BN_hex2bn(&value, iv.c_str());
	BN_add_word(value, init_add);
}

BigInteger::BigInteger(const BigInteger& copy)
{
	value = BN_dup(copy.value);
}

BigInteger::~BigInteger()
{
	BN_free(value);
}

BigInteger& BigInteger::operator++()
{
	BN_add_word(value, 1);
	return *this;
}

BigInteger& BigInteger::operator+(const BigInteger& add)
{
	BN_add(value, value, add.value);
	return *this;
}

BigInteger& BigInteger::operator+(const unsigned long val)
{
	BN_add_word(value, val);
	return *this;
}
void BigInteger::add(const unsigned long val)
{
	BN_add_word(value, val);
}

bool BigInteger::operator==(const BigInteger& cmpVal) const
{
	return BN_cmp(value, cmpVal.value) == 0;
}

int BigInteger::getBinValue(byte* bin_val) const
{
	return BN_bn2bin(value, bin_val);
}

char* BigInteger::c_str() const
{
	return BN_bn2hex(value);
}
